home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / BARMDI.PAK / ABOUT.C next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  275 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include "globals.h"            // prototypes specific to this application
  27. #include "resource.h"
  28.  
  29. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  30. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  31. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  32. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  33.  
  34. // About dialog message table definition.
  35. MSD rgmsdAbout[] =
  36. {
  37.     {WM_COMMAND,    MsgAboutCommand},
  38.     {WM_INITDIALOG, MsgAboutInit}
  39. };
  40.  
  41. MSDI msdiAbout =
  42. {
  43.     sizeof(rgmsdAbout) / sizeof(MSD),
  44.     rgmsdAbout,
  45.     edwpNone
  46. };
  47.  
  48. // About dialog command table definition.
  49. CMD rgcmdAbout[] =
  50. {
  51.     {IDOK,     CmdAboutDone},
  52.     {IDCANCEL, CmdAboutDone}
  53. };
  54.  
  55. CMDI cmdiAbout =
  56. {
  57.     sizeof(rgcmdAbout) / sizeof(CMD),
  58.     rgcmdAbout,
  59.     edwpNone
  60. };
  61.  
  62. // Module specific "globals"  Used when a variable needs to be
  63. // accessed in more than on handler function.
  64.  
  65. HFONT hFontCopyright;
  66.  
  67. //
  68. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  69. //
  70. //  PURPOSE: Displays the "About" dialog box
  71. //
  72. //  PARAMETERS:
  73. //    hwnd      - Window handle
  74. //    wCommand  - IDM_ABOUT (unused)
  75. //    wNotify   - Notification number (unused)
  76. //    hwndCtrl  - NULL (unused)
  77. //
  78. //  RETURN VALUE:
  79. //
  80. //    Always returns 0 - Message handled
  81. //
  82. //  COMMENTS:
  83. //    To process the IDM_ABOUT message, call DialogBox() to display the
  84. //    about dialog box.
  85.  
  86. #pragma argsused
  87. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  88. {
  89.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  90.     return 0;
  91. }
  92.  
  93.  
  94. //
  95. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  96. //
  97. //  PURPOSE:  Processes messages for "About" dialog box.
  98. //
  99. //  PARAMETERS:
  100. //    hdlg - window handle of the dialog box
  101. //    wMessage - type of message
  102. //    wparam - message-specific information
  103. //    lparam - message-specific information
  104. //
  105. //  RETURN VALUE:
  106. //    TRUE - message handled
  107. //    FALSE - message not handled
  108. //
  109. //  COMMENTS:
  110. //
  111. //     Display version information from the version section of the
  112. //     application resource.
  113. //
  114. //     Wait for user to click on "Ok" button, then close the dialog box.
  115. //
  116.  
  117. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  118. {
  119.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  120. }
  121.  
  122.  
  123. //
  124. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  125. //
  126. //  PURPOSE: To initialize the about box with version info from resources.
  127. //
  128. //  PARAMETERS:
  129. //    hwnd - The window handing the message.
  130. //    uMessage - The message number. (unused).
  131. //    wparam - Message specific data (unused).
  132. //    lparam - Message specific data (unused).
  133. //
  134. //  RETURN VALUE:
  135. //    Always returns 0 - message handled.
  136. //
  137. //  COMMENTS:
  138. //    Uses the version apis to retrieve version information for
  139. //    each of the static text boxes in the about box.
  140. //
  141.  
  142. #pragma argsused
  143. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  144. {
  145.     #define POINTSIZE 8
  146.  
  147.     char  szFullPath[256];
  148.     DWORD dwVerHnd;
  149.     DWORD dwVerInfoSize;
  150.     HDC   hDC;
  151.     int   iLogPixelsY, iPointSize;
  152.  
  153.     // Center the dialog over the application window
  154.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  155.  
  156.     // Set the copyright font to something smaller than default
  157.     hDC = GetDC(hdlg);
  158.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  159.     ReleaseDC(hdlg, hDC);
  160.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  161.     iPointSize *= -1;
  162.  
  163.     hFontCopyright = CreateFont(iPointSize,
  164.                                 0, 0, 0,
  165.                                 FW_BOLD,
  166.                                 0, 0, 0, 0,
  167.                                 0, 0, 0, 0,
  168.                                 "Arial");
  169.  
  170.     SendDlgItemMessage(hdlg, 
  171.                        IDD_VERLAST, 
  172.                        WM_SETFONT, 
  173.                        (WPARAM)hFontCopyright,
  174.                        0L);
  175.  
  176.     // Get version information from the application
  177.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  178.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  179.     if (dwVerInfoSize)
  180.     {
  181.         // If we were able to get the information, process it:
  182.         HANDLE  hMem;
  183.         LPVOID  lpvMem;
  184.         char    szGetName[256];
  185.         int     cchRoot;
  186.         int     i;
  187.  
  188.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  189.         lpvMem = GlobalLock(hMem);
  190.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  191.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  192.         cchRoot = lstrlen(szGetName);
  193.  
  194.         // Walk through the dialog items that we want to replace:
  195.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  196.         {
  197.             BOOL  fRet;
  198.             UINT  cchVer = 0;
  199.             LPSTR lszVer = NULL;
  200.             char  szResult[256];
  201.  
  202.             GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  203.             lstrcpy(&szGetName[cchRoot], szResult);
  204.             fRet = VerQueryValue(lpvMem, szGetName, (LPVOID) &lszVer, &cchVer);
  205.  
  206.             if (fRet && cchVer && lszVer)
  207.             {
  208.                 // Replace dialog item text with version info
  209.                 lstrcpy(szResult, lszVer);
  210.                 SetDlgItemText(hdlg, i, szResult);
  211.             }
  212.         }
  213.         GlobalUnlock(hMem);
  214.         GlobalFree(hMem);
  215.     }
  216.     return TRUE;
  217. }
  218.  
  219. //
  220. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  221. //
  222. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  223. //
  224. //  PARAMETERS:
  225. //    hwnd - The window handing the message.
  226. //    uMessage - The message number. (unused).
  227. //    wparam - Message specific data (unused).
  228. //    lparam - Message specific data (unused).
  229. //
  230. //  RETURN VALUE:
  231. //    Always returns 0 - message handled.
  232. //
  233. //  COMMENTS:
  234. //    Uses this DipsCommand function defined in wndproc.c combined
  235. //    with the cmdiAbout structure defined in this file to handle
  236. //    the command messages for the about dialog box.
  237. //
  238.  
  239. #pragma argsused
  240. LRESULT MsgAboutCommand(HWND   hwnd, 
  241.                         UINT   uMessage, 
  242.                         WPARAM wparam, 
  243.                         LPARAM lparam)
  244. {
  245.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  246. }
  247.  
  248. //
  249. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  250. //
  251. //  PURPOSE: Free the about box and related data.
  252. //
  253. //  PARAMETERS:
  254. //    hwnd - The window handling the command.
  255. //    wCommand - The command to be handled (unused).
  256. //    wNotify   - Notification number (unused)
  257. //    hwndCtrl - NULL (unused).
  258. //
  259. //  RETURN VALUE:
  260. //    Always returns TRUE.
  261. //
  262. //  COMMENTS:
  263. //    Calls EndDialog to finish the dialog session.
  264. //
  265.  
  266. #pragma argsused
  267. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  268. {
  269.     if (hFontCopyright)
  270.        DeleteObject(hFontCopyright);
  271.  
  272.     EndDialog(hdlg, TRUE);          // Exit the dialog
  273.     return TRUE;
  274. }
  275.